package info.techgeek.labs.java5Features.thread.cifortify;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

public class TaskThreadPoolExecuter {
	int poolSize = 2;

	int maxPoolSize = 10;

	long keepAliveTime = 10;
	private static final TaskThreadPoolExecuter POOL_EXECUTOR = new TaskThreadPoolExecuter();
	ThreadPoolExecutor threadPool = null;

	public static TaskThreadPoolExecuter getInstance() {
		return POOL_EXECUTOR;
	}

	static final int CAPACITY = 1000;
	private BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(CAPACITY);

	private TaskThreadPoolExecuter() {
		threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize,	keepAliveTime, TimeUnit.SECONDS, queue);
		
		System.out.println("***************************************************************");
		System.out.println("*   TaskThreadPoolExecuter ThreadPool Created  ****************");
		System.out.println("*****************************************************************");
	}

	public void runTask(Runnable task) {
		// System.out.println("Task count.."+threadPool.getTaskCount() );
		// System.out.println("Queue Size before assigning the task.."+queue.size()
		// );
		threadPool.execute(task);
	}

	public void shutDown() {
		threadPool.shutdown();
	}
}

